﻿'
' Boogaloo® - http://www.mindfly.com
' Copyright (c) 2008
' by Mindfly, Inc.
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
' INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
' DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
' SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
' SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
' WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
' THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Imports System.Xml
Imports System.Web

Namespace Rss

    ''' <summary>
    ''' Stores information about a web service that supports the rssCloud interface which can be implemented in HTTP-POST, XML-RPC or SOAP 1.1
    ''' </summary>
    Public Class RssCloud
        Inherits RssBase


        Public Sub New(ByVal domain As String, ByVal port As Integer, ByVal path As String, ByVal registerProcedure As String, ByVal protocol As String)
            Me.domain = domain
            Me.port = port
            Me.path = path
            Me.registerProcedure = registerProcedure
            Me.protocol = protocol
        End Sub


        Public Function ToXmlString() As String
            Return String.Format("<cloud domain=""{0}"" port=""{1}"" path=""{2}"" registerProcedure=""{3}"" protocol=""{4}"" />", GetSafeXml(domain), GetSafeXml(port), GetSafeXml(path), GetSafeXml(registerProcedure), GetSafeXml(protocol))
        End Function

        ''' <summary>
        ''' Returns an instantiation of RssCloud if item contains a cloud child element
        ''' </summary>
        Public Shared Function GetRssCloud(ByVal item As XmlNode) As RssCloud
            Dim cloud As RssCloud = Nothing
            If item.SelectSingleNode("cloud") IsNot Nothing Then
                With CType(item.SelectSingleNode("cloud"), XmlElement)
                    cloud = New RssCloud(.GetAttribute("domain"), CType(.GetAttribute("port"), Integer), .GetAttribute("path"), .GetAttribute("registerProcedure"), .GetAttribute("protocol"))
                End With
            End If
            Return cloud
        End Function


#Region "Properties"


        ''' <summary>
        ''' Cloud domain / host
        ''' </summary>
        Private _domain As String
        Public Property domain() As String
            Get
                Return _domain
            End Get
            Set(ByVal value As String)
                _domain = value
            End Set
        End Property

        ''' <summary>
        ''' TCP port the cloud is running on
        ''' </summary>
        Private _port As Integer = 80
        Public Property port() As Integer
            Get
                Return _port
            End Get
            Set(ByVal value As Integer)
                _port = value
            End Set
        End Property

        ''' <summary>
        ''' Path to webservice on the domain (virtual path: ex. /RPC2)
        ''' </summary>
        Private _path As String
        Public Property path() As String
            Get
                Return _path
            End Get
            Set(ByVal value As String)
                _path = value
            End Set
        End Property

        ''' <summary>
        ''' procedure to call
        ''' </summary>
        Private _registerProcedure As String
        Public Property registerProcedure() As String
            Get
                Return _registerProcedure
            End Get
            Set(ByVal value As String)
                _registerProcedure = value
            End Set
        End Property

        ''' <summary>
        ''' Webservice protocal (xml-rpc, soap, http-post)
        ''' </summary>
        Private _protocol As String = "xml-rpc"
        Public Property protocol() As String
            Get
                Return _protocol
            End Get
            Set(ByVal value As String)
                _protocol = value
            End Set
        End Property


#End Region
    End Class


End Namespace